package com.resys.server.controller.admin;

import com.resys.entity.dto.StaffInfodto;
import com.resys.entity.dto.TokenUserInfoDto;
import com.resys.entity.po.Customer;
import com.resys.entity.po.User;
import com.resys.entity.query.CustomerQuery;
import com.resys.entity.query.UserQuery;
import com.resys.entity.vo.PaginationResultVO;
import com.resys.entity.vo.ResponseVO;
import com.resys.exception.BusinessException;
import com.resys.server.controller.ABaseController;
import com.resys.service.CustomerService;
import com.resys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("StaffController")
@Slf4j
@RequestMapping("/admin/staff")
@Api(tags = "管理员模块-管理员工信息接口")
public class StaffController extends ABaseController {
    @Resource
    private UserService userService;
    @ApiOperation("获取员工表")
    @GetMapping
    public ResponseVO list(Integer pageNo) {
        UserQuery query = new UserQuery();
        query.setRole(1);
        query.setPageNo(pageNo);
        query.setPageSize(15);
        PaginationResultVO list = userService.findListByPage(query);
        return getSuccessResponseVO(list);
    }
    @ApiOperation("模糊搜索客户列表")
    @GetMapping("/search")
    public ResponseVO search(String StaffFuzzyRealName,Integer pageNo) {
        UserQuery query = new UserQuery();
        query.setRole(1);
        query.setPageNo(pageNo);
        query.setPageSize(15);
        query.setRealNameFuzzy(StaffFuzzyRealName);
        PaginationResultVO list = userService.findListByPage(query);
        return getSuccessResponseVO(list);
    }
    @ApiOperation("获取新注册员工户账号")
    @GetMapping("/waitPass")
    public ResponseVO waitPass(Integer pageNo) {
        UserQuery query = new UserQuery();
        query.setRole(1);
        query.setPageNo(pageNo);
        query.setPageSize(15);
        query.setAccountStatus(1);
        PaginationResultVO list = userService.findListByPage(query);
        return getSuccessResponseVO(list);
    }
    @ApiOperation("改变客户状态")
    @PostMapping("/changeStatus")
    public ResponseVO changeStatus(String userId,Integer status) {
        User user = new User();
        user.setAccountStatus(status);
        userService.updateUserByUserId(user,userId);
        return getSuccessResponseVO("修改成功");
    }
    @ApiOperation("修改员工信息")
    @PostMapping("/update")
    public ResponseVO update(@RequestBody StaffInfodto staffInfodto) {
        User user = userService.getUserByUserId(staffInfodto.getUserId());
        if (user == null) {
            throw new BusinessException("用户不存在");

        }
        user.setRealName(staffInfodto.getRealName());
        user.setPhone(staffInfodto.getPhone());
        userService.updateUserByUserId(user,user.getUserId());

        return getSuccessResponseVO("修改成功");

    }
    @ApiOperation("删除员工信息")
    @PostMapping("/delete")
    public ResponseVO delete(String userId) {
        userService.deleteUserByUserId(userId);
        return getSuccessResponseVO("删除成功");
    }
}
